package com.celesea.workflow.core.service;

import com.celesea.framework.service.AbstractBaseService;
import com.celesea.framework.util.EnvUtil;
import com.celesea.workflow.core.dao.WorkflowNodeActionDao;
import com.celesea.workflow.core.entity.WorkflowNode;
import com.celesea.workflow.core.entity.WorkflowNodeAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author JackYuan
 * @create 2017-11-28 12:53
 */
@Service
public class WorkflowNodeActionServiceImpl extends
        AbstractBaseService<WorkflowNodeAction> implements WorkflowNodeActionService {

    @Autowired
    private WorkflowNodeActionDao workflowNodeActionDao;

    @Override
    public int doDeleteByDefine(String id) {
        Example example = new Example(WorkflowNodeAction.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("tenantId", EnvUtil.getTenantId())
                .andEqualTo("wfId", id);
        return workflowNodeActionDao.deleteByExample(example);
    }

    @Override
    public List<WorkflowNodeAction> selectByNode(WorkflowNode node) {
        Example example = new Example(WorkflowNodeAction.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("tenantId", EnvUtil.getTenantId())
                .andEqualTo("wfNodeId", node.getId());
        example.orderBy("sort").asc();
        return workflowNodeActionDao.selectByExample(example);
    }
}
